﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReporterEngine
{
    public partial class sQuery
    {
        public string[] GetArgValuesForType(List<LexPath.PathToken> args)
        {
            var result = new List<string>();

            foreach(var arg in args)
            {
                if (arg.Kind == LexPath.TokenKind.Property || arg.Kind == LexPath.TokenKind.String)
                {
                    var replaced = arg.PathExp.Replace("\"", "")
                        .Replace("'", "")
                        .Replace("’", "")
                        .Replace("‘", "")
                        .Replace("”", "")
                        .Replace("“", "")
                        .Replace("„", "");

                    result.Add(replaced);//‚‘
                }

                ReporterEngine.LexPath.PathToken tempArg = null;

                if (arg.Next != null && arg.Next.IsNextArg)
                    tempArg = arg.Next;

                while(tempArg != null)
                {
                    if (tempArg.Kind == LexPath.TokenKind.Property || tempArg.Kind == LexPath.TokenKind.String)
                    {
                        result.Add(tempArg.PathExp.Replace("\"", "")
                        .Replace("'", "")
                        .Replace("’", "")
                        .Replace("‘", "")
                        .Replace("”", "")
                        .Replace("“", "")
                        .Replace("„", ""));
                    }

                    if (tempArg.Next != null && tempArg.Next.IsNextArg)
                        tempArg = tempArg.Next;
                    else
                        tempArg = null;
                }
            }
            
            return result.ToArray();
        }

        public static string RemoveAllQuotations(string value)
        {
            if (string.IsNullOrEmpty(value))
                return value;

            return value.Replace("\"", "")
                .Replace("'", "")
                .Replace("’", "")
                .Replace("‘", "")
                .Replace("”", "")
                .Replace("“", "")
                .Replace("„", "");
        }

        public static string RemoveOnlyStringQuotations(string value)
        {
            if (string.IsNullOrEmpty(value))
                return value;

            return value.Replace("\"", "")
                .Replace("”", "")
                .Replace("“", "")
                .Replace("„", "");
        }

        public string[] GetArgValuesForType(LexPath.PathToken arg)
        {
            var result = new List<string>();


            if (arg.Kind == LexPath.TokenKind.Property || arg.Kind == LexPath.TokenKind.String || arg.Kind == LexPath.TokenKind.UsedByReference)
            {
                result.Add(arg.PathExp.Replace("\"", "").Replace("'", ""));
            }

            ReporterEngine.LexPath.PathToken tempArg = null;

            if (arg.Next != null && arg.Next.IsNextArg)
                tempArg = arg.Next;

            while (tempArg != null)
            {
                if (tempArg.Kind == LexPath.TokenKind.Property || tempArg.Kind == LexPath.TokenKind.String)
                {
                    result.Add(tempArg.PathExp.Replace("\"", "").Replace("'", ""));
                }


                if (tempArg.Next != null && tempArg.Next.IsNextArg)
                    tempArg = tempArg.Next;
                else
                    tempArg = null;
            }

            return result.ToArray();
        }
    }
}
